"""
Python绘制词云图展示射雕英雄传高频词语
使用中文分词库Python库：jieba，自然语言处理必备，https://github.com/fxsjy/jieba
"""
import pandas as pd
import pyecharts.options as opts
from pyecharts.charts import WordCloud

# import jieba

# 1、将小说文字分词
fin = open('', encoding='utf-8')
txt = fin.read()
print(txt[:100])

# 使用TF/IDF提取关键词
word_weights = jieba.analyse.extract_tags(
    txt, topK=50, withWeight=True)

# 2、绘制词云图
word_cloud = (
    WordCloud()
    .add(series_name="高频词语",
         data_pair=word_weights, word_size_range=[10, 50])
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="射雕英雄传-高频词云图",
            title_textstyle_opts=opts.TextStyleOpts(font_size=23),
            pos_left='center')
    )
)

word_cloud.render('./Files/my_wordCloud.html')
